package com.oocl.shopping.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.shopping.pojo.Customer;
import com.oocl.shopping.repository.BooksDB;
import com.oocl.shopping.repository.OrdersDB;
import com.oocl.shopping.service.CustomerService;
import com.oocl.shopping.service.impl.CustomerServiceImpl;

/**
 * Servlet implementation class BuyServlet
 */
public class BuyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CustomerService service;    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BuyServlet() {
    	service = new CustomerServiceImpl();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String custId = ((Customer)request.getSession().getAttribute("cust")).getId();
		
		service.addOrders(custId, OrdersDB.getOrdersMap());
		response.sendRedirect("../view/showbooks.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
